﻿using System;
using System.Data;
using Core.Library;

namespace DataObject.Product
{
    public class ProductController
    {
        /***************************************
        = Back End
        -------------------------------------- */
        public static void Product_Create(ProductObject o)
        {
            ProductDAL.Product_Create(o);
        }

        public static void Product_Update(ProductObject o)
        {
            ProductDAL.Product_Update(o);
        }

        public static void Product_Update_Status(int id, int status)
        {
            ProductDAL.Product_Update_Status(id, status);
        }

        public static void Product_Update_ImagePath(int id, string imgPath)
        {
            ProductDAL.Product_Update_ImagePath(id, imgPath);
        }

        public static void Product_Delete(int productId)
        {
            ProductDAL.Product_Delete(productId);
        }

        public static ProductObject Product_GetById(int productId)
        {
            return ObjectHelper.FillObject<ProductObject>(ProductDAL.Product_GetById(productId));
        }

        public static string GetProductName(int productId)
        {
            try { return Product_GetById(productId).Name; }
            catch { return string.Empty; }    
        }

        public static int Product_GetStatistic(int status)
        {
            return ProductDAL.Product_GetStatistic(status);
        }


        /***************************************
        = Front End
        -------------------------------------- */

        public static DataTable Product_ListTopHightlightProduct(int count)
        {
            return ProductDAL.Product_ListTopHightlightProduct(count);
        }

        public static DataTable Product_TopProductByCategory(int categoryId, int count)
        {
            return ProductDAL.Product_TopProductByCategory(categoryId, count);
        }

        public static DataTable Product_ListPaginationByCategory(string keyword, int categoryId, int status, int type, int pageIndex, int pageSize, ref int totalRecords)
        {
            return ProductDAL.Product_ListPaginationByCategory(keyword, categoryId, status, type, pageIndex, pageSize, ref totalRecords);
        }

        public static DataTable Product_ListPaginationRelatedProduct(int categoryId, int productId, int pageIndex, int pageSize, ref int totalRecords)
        {
            return ProductDAL.Product_ListPaginationRelatedProduct(categoryId, productId, pageIndex, pageSize, ref totalRecords);
        }
    }
}
